/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import { concat } from "lodash-es";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { page as merchantPage } from "$/attractions/commerce/api/commerceMerchant.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaUploadImage from "@/components/ma-upload-image/index.vue";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "商户名称",
      prop: "merchant_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: merchantPage,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.merchant_name || `商户名称${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择商户名称",
        clearable: true,
        multiple: false,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择商户" }],
      },
    },
    {
      label: "费用类型",
      prop: "cost_type",
      render: () => MaDictSelect,
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "费用类型" }),
        data: [
          { label: "水费", value: 1 },
          { label: "电费", value: 2 },
          { label: "气费", value: 3 },
          { label: "其他", value: 4 },
        ],
      },
      itemProps: {
        rules: [{ required: true, message: "请选择费用类型" }],
      },
    },
    {
      label: "用量",
      prop: "cost_usage",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "用量" }) },
      itemProps: { rules: [{ required: true, message: "请输入用量" }] },
    },
    {
      label: "单价",
      prop: "cost_price",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "单价" }) },
      itemProps: { rules: [{ required: true, message: "请输入单价" }] },
    },
    {
      label: "表读数",
      prop: "cost_meter_reading",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "表读数" }) },
    },
    {
      label: "总费用",
      prop: "total_amount",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "总费用" }) },
      itemProps: { rules: [{ required: true, message: "请输入总费用" }] },
    },
    {
      label: "缴费日期",
      prop: "payment_date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "缴费日期" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      mode: "date",
      showTime: false,
    },
    {
      label: "付款方式",
      prop: "payment_method",
      render: () => MaDictSelect,
      renderProps: {
        placeholder: t("form.pleaseSelect", { msg: "付款方式" }),
        data: [
          { label: "银行转账", value: 1 },
          { label: "微信支付", value: 2 },
          { label: "支付宝支付", value: 3 },
          { label: "现金", value: 4 },
          { label: "其他付款方式", value: 5 },
        ],
      },
      itemProps: { rules: [{ required: true, message: "请选择付款方式" }] },
    },
    {
      label: "发票号",
      prop: "invoice_id",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "发票号" }) },
    },
    {
      label: "抄表照片",
      prop: "meter_photos",
      render: () => MaUploadImage,
      renderProps: {
        placeholder: "请上传抄表照片",
        multiple: false,
        limit: 1,
        accept: "image/*",
        tips: "支持jpg、png、gif格式，文件大小不超过5MB",
      },
    },
    {
      label: "账单照片",
      prop: "bills_photos",
      render: () => MaUploadImage,
      renderProps: {
        placeholder: "请上传账单照片",
        multiple: false,
        limit: 1,
        accept: "image/*",
        tips: "支持jpg、png、gif格式，文件大小不超过5MB",
      },
    },
  ]);
}
